export default {
  data() {
    return {
      isFixed: false
    }
  },
  mounted() {
    window.addEventListener('scroll', this.handleScroll)
  },
  methods: {
    // 页面滚动监听
    handleScroll() {
      const scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop // 滚动条偏移量
      // const offsetTop = document.querySelector('#tabFixed').offsetTop // 要滚动到顶部吸附的元素的偏移量
      const container = document.querySelector('.top-container')
      const offsetTop = container && container.offsetHeight
      this.isFixed = scrollTop > offsetTop // 如果滚动到顶部46像素时，this.isFixed就为true
    }
  }
}
